package com.geostar.constructionland.analyse.factory;

import com.geostar.constructionland.analyse.config.SpringUtil;
import com.geostar.constructionland.analyse.entity.model.AnalyseModel;
import com.geostar.constructionland.analyse.service.AnalyseChain;
import com.geostar.constructionland.analyse.service.analyse.impl.Analyse;
import com.geostar.constructionland.analyse.service.handler.IResultHandler;
import com.geostar.constructionland.analyse.service.handler.impl.*;
import com.geostar.constructionland.analyse.service.spatiaanalyst.ISpatialAnalyst;
import com.geostar.constructionland.analyse.service.spatiaanalyst.impl.*;
import com.geostar.constructionland.common.global.AnalyseType;
import com.geostar.constructionland.common.util.CloneUtil;
import org.springframework.stereotype.Component;


/**
 * @author yelll
 * @since 2020-5-27 11:02
 **/
@Component
public class AnalyseFactory {
    public static AnalyseChain getSptAlyParam(AnalyseModel analyseModel) {
        /***读取字典 ，查找影射关系**/
        AnalyseType analyseType = AnalyseType.valueOf(analyseModel.getFxlxMapped());
        AnalyseChain analyseChain = new AnalyseChain();
        switch (analyseType) {
            case XZQFX:
                /**行政区分析**/
                ISpatialAnalyst xzqSptAnalyse = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler xzqResultHandler = SpringUtil.getBean(XzqHandler.class);
                Analyse xzqAnalyse = new Analyse(xzqSptAnalyse, xzqResultHandler, analyseModel);
                analyseChain.addAnalyse(xzqAnalyse);
                break;
            case CDZDFX:
                /**重叠宗地分析**/
                ISpatialAnalyst cdzdfx_overlapLandAnalyse = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler overlapHandler = SpringUtil.getBean(OverlapLandHandler.class);
                Analyse cdzd_overlapLandAnalyse = new Analyse(cdzdfx_overlapLandAnalyse, overlapHandler, analyseModel);
                analyseChain.addAnalyse(cdzd_overlapLandAnalyse);
                break;
            case TZHDLGDFX:
                /***重叠宗地分析*/
                AnalyseModel analyseModel_cdzd = new AnalyseModel();
                CloneUtil.copyProperties(analyseModel, analyseModel_cdzd);
                analyseModel_cdzd.setAnalyseVersion("1.0");
                analyseModel_cdzd.setFxlx(AnalyseType.CDZDFX.getCode());
                analyseModel_cdzd.setFxlxMapped(AnalyseType.CDZDFX.getCode());
                ISpatialAnalyst cdzdSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler cdzdResultHandler = SpringUtil.getBean(CdZdFxHandler.class);
                Analyse cdZdAnalyse = new Analyse(cdzdSptAly, cdzdResultHandler, analyseModel_cdzd);
                analyseChain.addAnalyse(cdZdAnalyse);

                /***调整后地类耕地分析*/
                ISpatialAnalyst tzhDlGdSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler resultHandler = (IResultHandler) SpringUtil.getBean(AnalyseType.TZHDLGDFX.getCode() + "Ver" + analyseModel.getAnalyseVersion());
                Analyse tzhDlGdAnalyse = new Analyse(tzhDlGdSptAly, resultHandler, analyseModel);
                analyseChain.addAnalyse(tzhDlGdAnalyse);

                /**
                 * 地类分析1.0 版本 不需要做地类毛面积分析
                 * 地类分析2.0 版本 需要做1.0版本地类毛面积
                 * 地类分析3.0 版本 需要做2.0版本地类毛面积
                 */
                /**调整后地类分析**/
                if (analyseModel.getAnalyseVersion().equals("2.0") || analyseModel.getAnalyseVersion().equals("3.0")) {
                    AnalyseModel analyseModel_mmj = new AnalyseModel();
                    CloneUtil.copyProperties(analyseModel, analyseModel_mmj);
                    /**地类毛面积*/
                    ISpatialAnalyst mmjjs = SpringUtil.getBean(MmjfxSptAnalyse.class);
                    IResultHandler mmjHandler = (IResultHandler) SpringUtil.getBean(AnalyseType.DLMJJFX.getCode() + "Ver1.0");
                    analyseModel_mmj.setAnalyseVersion("1.0");
                    if (analyseModel.getAnalyseVersion().equals("3.0")) {
                        /***毛面积还原分析*/
                        mmjHandler = (IResultHandler) SpringUtil.getBean(AnalyseType.DLMJJFX.getCode() + "Ver2.0");
                        analyseModel_mmj.setAnalyseVersion("2.0");
                    }
                    analyseModel_mmj.setFxlx(AnalyseType.DLMJJFX.getCode());
                    analyseModel_mmj.setFxlxMapped(AnalyseType.DLMJJFX.getCode());
                    Analyse mmjAnalyse = new Analyse(mmjjs, mmjHandler, analyseModel_mmj);
                    analyseChain.addAnalyse(mmjAnalyse);
                }
                break;
            case MJJS:
                /**面积计算**/
                ISpatialAnalyst areaCalSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler areaCalHandler = SpringUtil.getBean(AreaCalHandler.class);
                Analyse areaCal = new Analyse(areaCalSptAly, areaCalHandler, analyseModel);
                analyseChain.addAnalyse(areaCal);
                break;
            case ZRBHQFX:
                /**自然保护区分析**/
                ISpatialAnalyst zrbhqSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler zrbhqHandle = SpringUtil.getBean(ZrbhqHandler.class);
                Analyse zrbhqAnalyze = new Analyse(zrbhqSptAly, zrbhqHandle, analyseModel);
                analyseChain.addAnalyse(zrbhqAnalyze);
                break;
            case LYSTBHHXFX:
                /**陆域生态保护红线分析**/
                ISpatialAnalyst lystbhhxSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler lystbhhxHandle = SpringUtil.getBean(LystbhhxHandle.class);
                Analyse lystbhhxAnalyze = new Analyse(lystbhhxSptAly, lystbhhxHandle, analyseModel);
                analyseChain.addAnalyse(lystbhhxAnalyze);
                break;
            case HYSTBHHXFX:
                /**海洋生态保护红线分析**/
                ISpatialAnalyst hystbhhxSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler hystbhhxHandle = SpringUtil.getBean(HystbhhxHandle.class);
                Analyse hystbhhxAnalyze = new Analyse(hystbhhxSptAly, hystbhhxHandle, analyseModel);
                analyseChain.addAnalyse(hystbhhxAnalyze);
                break;
            case DQHPFX:
                /**低丘缓坡分析**/
                ISpatialAnalyst dqhpSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler dqhpHandler = SpringUtil.getBean(DqhpHandler.class);
                Analyse dqhpAnalyse = new Analyse(dqhpSptAly, dqhpHandler, analyseModel);
                analyseChain.addAnalyse(dqhpAnalyse);
                break;
            case GHDLFX:
                /**规划地类分析*/
                ISpatialAnalyst ghdlSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler ghdlHandler = SpringUtil.getBean(GhdlHandler.class);
                Analyse ghdlAnalyse = new Analyse(ghdlSptAly, ghdlHandler, analyseModel);
                analyseChain.addAnalyse(ghdlAnalyse);
                break;
            case YJJBNTFX:
                /**永久基本农田分析**/
                ISpatialAnalyst yjjbntSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler yjjbntHandle = SpringUtil.getBean(YjjbntHandler.class);
                Analyse yjjbntAnalyse = new Analyse(yjjbntSptAly, yjjbntHandle, analyseModel);
                analyseChain.addAnalyse(yjjbntAnalyse);
                break;
            case YJJBNTBHFX:
                /**永久基本农田补划分析**/
                ISpatialAnalyst yjjbntbhSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler yjjbntbhHandle = SpringUtil.getBean(YjjbntbhHandler.class);
                Analyse yjjbntbhAnalyse = new Analyse(yjjbntbhSptAly, yjjbntbhHandle, analyseModel);
                analyseChain.addAnalyse(yjjbntbhAnalyse);
                break;
            case ZPHXFX:
                /**在批红线分析**/
                ISpatialAnalyst zphxSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler zphxHandler = SpringUtil.getBean(ZphxHandler.class);
                Analyse zphxAnalyse = new Analyse(zphxSptAly, zphxHandler, analyseModel);
                analyseChain.addAnalyse(zphxAnalyse);
                break;
            case YPYSFX:
                /**已批预审分析**/
                ISpatialAnalyst ypysSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler ypysHandler = SpringUtil.getBean(YpysHandler.class);
                Analyse ypysAnalyse = new Analyse(ypysSptAly, ypysHandler, analyseModel);
                analyseChain.addAnalyse(ypysAnalyse);
                break;
            case JSYDGZQFX:
                /**建设用地管制区分析**/
                ISpatialAnalyst jsydgzqSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler jsydgzqHandler = SpringUtil.getBean(JsydgzqHandler.class);
                Analyse jsydgzqAnalyse = new Analyse(jsydgzqSptAly, jsydgzqHandler, analyseModel);
                analyseChain.addAnalyse(jsydgzqAnalyse);
                break;
            case ZYGDFX:
                /**占用耕地分析**/
                ISpatialAnalyst zygdSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler zygdHandler = SpringUtil.getBean(ZygdHandler.class);
                Analyse zygdAnalyse = new Analyse(zygdSptAly, zygdHandler, analyseModel);
                analyseChain.addAnalyse(zygdAnalyse);
                break;
            case GBZNTFX:
                /**高标准农田分析**/
                ISpatialAnalyst gbzntSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler gbzntHandler = SpringUtil.getBean(GbzntHandler.class);
                Analyse gbzntAnalyse = new Analyse(gbzntSptAly, gbzntHandler, analyseModel);
                analyseChain.addAnalyse(gbzntAnalyse);
                break;
            case CSZBYJJBNTFX:
                /**城市周边永久基本农田分析**/
                ISpatialAnalyst cszbyjjbntSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler cszbyjjbntHandler = SpringUtil.getBean(CszbyjjbntHandler.class);
                Analyse cszbjyjbntAnalyse = new Analyse(cszbyjjbntSptAly, cszbyjjbntHandler, analyseModel);
                analyseChain.addAnalyse(cszbjyjbntAnalyse);
                break;
            case YPHXFX:
                /**重叠已批红线分析***/
                AnalyseModel analyseModel_czyp = new AnalyseModel();
                CloneUtil.copyProperties(analyseModel, analyseModel_czyp);
                analyseModel_czyp.setFxlx("CDYPHXFX");

                ISpatialAnalyst cdyphxSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler cdyphxHandler = SpringUtil.getBean(CdyphxHandler.class);
                Analyse cdyphxAnalyse = new Analyse(cdyphxSptAly, cdyphxHandler, analyseModel_czyp);
                analyseChain.addAnalyse(cdyphxAnalyse);

                /**已批红线分析***/
                ISpatialAnalyst yphxSptAly = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler yphxHandler = SpringUtil.getBean(YphxHandler.class);
                Analyse yphxAnalyse = new Analyse(yphxSptAly, yphxHandler, analyseModel);
                analyseChain.addAnalyse(yphxAnalyse);
                break;
            case LYFWFX:
                /**陆域范围分析**/
                ISpatialAnalyst lyfwfxSptAnalyse = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler lyfwfxResultHandler = SpringUtil.getBean(LyfwfxHandler.class);
                Analyse lyfwfxAnalyse = new Analyse(lyfwfxSptAnalyse, lyfwfxResultHandler, analyseModel);
                analyseChain.addAnalyse(lyfwfxAnalyse);
                break;
            case ZBQFX:
                /**整备区分析*/
                ISpatialAnalyst zbqfx = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler zbqhandler = SpringUtil.getBean(ZbqHandler.class);
                Analyse zbqAnalyse = new Analyse(zbqfx, zbqhandler, analyseModel);
                analyseChain.addAnalyse(zbqAnalyse);
                break;
            case YZFXLT:
                /**压占分析落图**/
                ISpatialAnalyst yzltfx = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler yzltfxHand = SpringUtil.getBean(YzfxltHandler.class);
                Analyse yzltfxAnalyse = new Analyse(yzltfx, yzltfxHand, analyseModel);
                analyseChain.addAnalyse(yzltfxAnalyse);
                break;
            case KJCC:
                /**压占分析落图**/
                ISpatialAnalyst kjccfx = SpringUtil.getBean(KjccSptAnalyse.class);
                IResultHandler kjccHandler = SpringUtil.getBean(KjccHandler.class);
                Analyse kjccAnalyse = new Analyse(kjccfx, kjccHandler, analyseModel);
                analyseChain.addAnalyse(kjccAnalyse);
                break;
            case STBHHXFX:
                /**生态保护红线分析**/
                ISpatialAnalyst stbhhxAnalyst = SpringUtil.getBean(CommonSptAnalyse.class);
                IResultHandler stbhhxHandle = SpringUtil.getBean(StbhhxHandle.class);
                Analyse stbhhxAnalyze = new Analyse(stbhhxAnalyst, stbhhxHandle, analyseModel);
                analyseChain.addAnalyse(stbhhxAnalyze);
                break;
            case YCYFQFX:
               /**地质灾害易发区分析**/
                ISpatialAnalyst dzzhyfqAnalyst = SpringUtil.getBean(CommonJsonParamPostAnalyst.class);
                IResultHandler dzzhyfqHandle = SpringUtil.getBean(DzzhyfHandler.class);
                Analyse dzzhyfqAnalyze =new Analyse(dzzhyfqAnalyst,dzzhyfqHandle,analyseModel);
                analyseChain.addAnalyse(dzzhyfqAnalyze);
                break;
            /**生态保护红线分析**/
            case MINE_STBHHXFX:
            /**省级地质公园分析**/
            case MINE_SJDZGYFX:
            /**国家地质公园分析**/
            /**地质灾害易发分区分析**/
            case MINE_YCYFQFX:
            /**矿产资源储备区分析**/
            case MINE_KCZYCBQFX:
            /**水源保护区分析**/
            case MINE_SYBHQFX:
            /**离子型稀土专项勘察区分析**/
            case MINE_LZXXTZXKCQFX:
            /**矿产资源储量范围分析**/
            case MINE_KCZYCLFWFX:
            /**重点勘查区分析**/
            case MINE_ZDKCQFX:
            /**国家规划矿区分析**/
            case MINE_GJGHKQFX:
            /**矿管重点矿区分析**/
            case MINE_ZDKQFX:
            /**自然保护区分析**/
            case MINE_ZRBHQFX:
            /**县级行政区划分析**/
            case MINE_XZQFX:
            /**矿管地市级行政区划分析**/
            case MINE_DSJXZQFX:
            /**矿管永久基本农田分析**/
            case MINE_YJJBNTFX:
            /**矿产资源禁止开采区分析**/
            case MINE_KCZYJZKCQFX:
            /**探矿权分析**/
            case MINE_TKQFX:
            /**采矿权分析**/
            case MINE_CKQFX:
            /**探（采）矿权矿区面积计算分析**/
            case MINE_TCKQMJJSFX:
                ISpatialAnalyst kgstbhhxAnalyst = SpringUtil.getBean(CommonMineralAnalyse.class);
                IResultHandler kgstbhhxHandle = SpringUtil.getBean(MineCommonHandler.class);
                Analyse kgstbhhxAnalyze = new Analyse(kgstbhhxAnalyst, kgstbhhxHandle, analyseModel);
                analyseChain.addAnalyse(kgstbhhxAnalyze);
                break;
            case MINE_GJJDZGYFX:
                // 先进性省级地址公园分析
                AnalyseModel analyseModel_sjdz = new AnalyseModel();
                CloneUtil.copyProperties(analyseModel, analyseModel_sjdz);
                analyseModel_sjdz.setFxlx(AnalyseType.MINE_SJDZGYFX.getCode());
                analyseModel_sjdz.setFxlxMapped(AnalyseType.MINE_SJDZGYFX.getCode());
                ISpatialAnalyst gjjdzgyAnalyst = SpringUtil.getBean(CommonMineralAnalyse.class);
                IResultHandler gjjdzgyHandle = SpringUtil.getBean(MineGjdzgyHandler.class);
                Analyse gjjdzgyAnalyze = new Analyse(gjjdzgyAnalyst, gjjdzgyHandle, analyseModel_sjdz);
                analyseChain.addAnalyse(gjjdzgyAnalyze);
                // 再进行国家级地址公园分析
                ISpatialAnalyst sjjdzgyAnalyst = SpringUtil.getBean(CommonMineralAnalyse.class);
                IResultHandler sjjdzgyHandle = SpringUtil.getBean(MineGjdzgyHandler.class);
                Analyse sjjdzgyAnalyze = new Analyse(sjjdzgyAnalyst, sjjdzgyHandle, analyseModel);
                analyseChain.addAnalyse(sjjdzgyAnalyze);
                break;
            default:
                break;
        }
        return analyseChain;
    }
}
